package com.banana.manager.forest.controller.chemical;

import com.banana.manager.forest.entity.chemical.DisburseBean;
import com.banana.manager.forest.entity.chemical.OutBean;
import com.banana.manager.forest.service.impl.chemical.DisburseServiceImpl;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/disburse")
public class DisburseController {

    @Resource
    private DisburseServiceImpl disburseService;

    @PostMapping("/addDisburse")
    public DisburseBean addDisburse(@RequestBody DisburseBean disburseBean, HttpServletRequest request){
        System.out.println(disburseBean);
        HttpSession session = request.getSession();
        List<OutBean> list = disburseBean.getOutBeans();
        disburseService.addDisburse(disburseBean,list);
        List<OutBean> newList = new ArrayList<>();
        session.setAttribute("outList",newList);
        return disburseBean;
    }

    @GetMapping("/showDisburse")
    public DisburseBean showOne(Integer disburseId){
        return disburseService.findOneDis(disburseId);
    }

    @GetMapping("/displayDisburse")
    public PageInfo<DisburseBean> showAllDisburse(Integer page, LocalDate start, LocalDate end, String disburseClass){
        return disburseService.findBlurPage(page, start, end, disburseClass);
    }
}
